<?php
namespace Common\Model;

use Think\Model\RelationModel;

class RecordModel extends RelationModel
{
    //关联到用户
    protected $_link = array(
        'user'=>array(
            'mapping_type'  => self::BELONGS_TO,
            'class_name'    => 'User',
            'foreign_key'   => 'user_id'
        )
    );

    /**
     * 获取可用快递账号
     * @author Mr.Alien
     * @return string
     */
    public static function getAvailableNo($user_id)
    {
        $info = M("Record")->where(array('status'=>1,'user_id'=>$user_id))->order("no asc")->find();
        if($info){
			M("Record")->where(array('id'=>$info['id']))->save(array('status'=>2));
            return $info['no'];
        }else{
            return 0;
        }
    }
}